#include <iostream>
#include <string>
#include <etcd/Client.hpp>
#include <etcd/KeepAlive.hpp>
#include <etcd/Response.hpp>
#include <thread>

int main()
{
    std::string etcd_host = "http://127.0.0.1:2379";

    // 创建客户端对象
    etcd::Client client(etcd_host);
    // 创建保活对象
    auto keep_alive = client.leasekeepalive(3).get();
    auto lease_id = keep_alive->Lease();

    // 新增
    auto resp1 = client.put("/service/user", "1270.0.0.1:8080", lease_id).get();
    if(resp1.is_ok() == 0)
    {
        std::cout << "put error" <<  resp1.error_message() << std::endl;
        return -1;
    }
    else
    {
        std::cout << "put success " << std::endl;
    }

    auto resp2 = client.put("/service/friend", "1270.0.0.1:8888").get();
    if(resp2.is_ok() == 0)
    {
        std::cout << "put error" <<  resp2.error_message() << std::endl;
        return -1;
    }
    else
    {
        std::cout << "put success " << std::endl;
    }

    std::this_thread::sleep_for(std::chrono::seconds(10));

    return 0;
}